FROM nvidia/cuda:12.1.1-cudnn8-devel-ubuntu22.04
ENV DEBIAN_FRONTEND=noninteractive

# 合并安装系统依赖、设置时区和更新 alternatives 到一个 RUN 指令
RUN sed -i s@/archive.ubuntu.com/@/mirrors.tuna.tsinghua.edu.cn/@g /etc/apt/sources.list && \
    apt-get update && \
    apt-get upgrade -y && \
    apt-get -y --no-install-recommends install \
        build-essential curl ffmpeg git libgl1 sudo tzdata vim wget && \
    ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    echo "Asia/Shanghai" > /etc/timezone && \
    # 安装Miniconda
    wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && \
    bash /tmp/miniconda.sh -b -p /usr/local/miniconda3 && \
    rm /tmp/miniconda.sh && \
    # 配置环境变量
    echo "export PATH=/usr/local/miniconda3/bin:\$PATH" >> /etc/profile.d/conda.sh && \
    # 创建conda环境并安装依赖
    conda create -y -n latentsync python=3.10.13 && \
    conda install -y -n latentsync -c conda-forge ffmpeg && \
    conda install -y -n latentsync pip && \
    # 清理缓存
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* 

# 设置conda环境路径
ENV PATH "/usr/local/miniconda3/envs/latentsync/bin:/usr/local/miniconda3/bin:${PATH}"

# 复制 requirements.txt 文件
COPY LatentSync/requirements.txt /LatentSync/requirements.txt

# 分步安装 Python 依赖
RUN pip install -r /LatentSync/requirements.txt && \
    pip cache purge

# 设置工作目录
WORKDIR /LatentSync

# 容器启动命令
CMD ["bash"]
